﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using QingzimaScenario;
using QingzimaLogicModel;

namespace QingzimaWebClient.Controllers
{
    public class HoutaiXinwenController : Controller
    {
        //
        // GET: /HoutaiXinwen/

        public ActionResult List(int pageIndex = 1)
        {
            int pageSize = 1;
            ViewBag.pageSize = pageSize;
            ViewBag.curPage = pageIndex;
            ViewBag.total = XinwenScenario.GetCount();

            //List<XinwenLM> xinwenLMList = XinwenScenario.GetXinwenList(pageSize, pageIndex).ToList();

            ViewBag.XinwenList = XinwenScenario.HuoquModels();

            return View();
        }

        public ActionResult Add()
        {
            return View();
        }

        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Add(XinwenLM xinwenLM)
        {
            if (string.IsNullOrEmpty(xinwenLM.Biaoti))
            {
                ViewBag.State = "请输入新闻标题";
            }
            else
            {
                xinwenLM.Neirong = Request.Form.Get("HtmlTextArea");

                XinwenScenario.Tianjia(xinwenLM);
                return RedirectToAction("List");
            }
            return View();
        }

        public ActionResult Update(string key)
        {
            XinwenLM XinwenLM = XinwenScenario.HuoquByKey(key);
            ViewBag.Neirong = XinwenLM.Neirong;
            return View(XinwenLM);
        }

        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Update(XinwenLM XinwenLM)
        {
            XinwenLM.Neirong = Request.Form.Get("HtmlTextArea");

            XinwenScenario.Tianjia(XinwenLM);
            return RedirectToAction("List");
        }

        public ActionResult Del(string key)
        {
            XinwenScenario.Shanchu(key);
            return RedirectToAction("List");
        }
    }
}
